Skip to content

f-aws-workmail-domain, f-aws-workmail-default-domain#46931

Open
subham-ibmhc wants to merge 15 commits intomainfrom
f-aws-workmail-domain
Open

f-aws-workmail-domain, f-aws-workmail-default-domain#46931
subham-ibmhc wants to merge 15 commits intomainfrom
f-aws-workmail-domain

Conversation

@subham-ibmhc
Copy link
Contributor

Rollback Plan

If a change needs to be reverted, we will publish an updated version of the library.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

Description

  • aws_workmail_domain - Used to register and manage domains for workmail organization

  • aws_workmail_default_domain - Used to update default domain for workmail organization (this does not register a new domain)

  • Adds RI and List support for aws_workmail_domain

  • Was not able to find a reliable way to test update scenario for default_domain resource as remote API needs a verified domain before it can be set as default for an organization.

Relations

Relates #6430

References

https://docs.aws.amazon.com/workmail/latest/APIReference/API_DeregisterMailDomain.html
https://docs.aws.amazon.com/workmail/latest/APIReference/API_RegisterMailDomain.html
https://docs.aws.amazon.com/workmail/latest/APIReference/API_GetMailDomain.html
https://docs.aws.amazon.com/workmail/latest/APIReference/API_UpdateDefaultMailDomain.html

Output from Acceptance Testing

% make t T=TestAccWorkMailDomain_ K=workmail
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-aws-workmail-domain 🌿...
TF_ACC=1 go1.25.8 test ./internal/service/workmail/... -v -count 1 -parallel 20 -run='TestAccWorkMailDomain_'  -timeout 360m -vet=off
2026/03/12 02:15:35 Creating Terraform AWS Provider (SDKv2-style)...
2026/03/12 02:15:35 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccWorkMailDomain_basic
=== PAUSE TestAccWorkMailDomain_basic
=== RUN   TestAccWorkMailDomain_disappears
=== PAUSE TestAccWorkMailDomain_disappears
=== CONT  TestAccWorkMailDomain_basic
=== CONT  TestAccWorkMailDomain_disappears
--- PASS: TestAccWorkMailDomain_basic (53.85s)
--- PASS: TestAccWorkMailDomain_disappears (65.15s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/workmail   70.307s
% make t T=TestAccWorkMailDomain_Identity_ K=workmail
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-aws-workmail-domain 🌿...
TF_ACC=1 go1.25.8 test ./internal/service/workmail/... -v -count 1 -parallel 20 -run='TestAccWorkMailDomain_Identity_'  -timeout 360m -vet=off
2026/03/13 18:40:46 Creating Terraform AWS Provider (SDKv2-style)...
2026/03/13 18:40:46 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccWorkMailDomain_Identity_basic
=== PAUSE TestAccWorkMailDomain_Identity_basic
=== RUN   TestAccWorkMailDomain_Identity_regionOverride
=== PAUSE TestAccWorkMailDomain_Identity_regionOverride
=== CONT  TestAccWorkMailDomain_Identity_basic
=== CONT  TestAccWorkMailDomain_Identity_regionOverride
--- PASS: TestAccWorkMailDomain_Identity_basic (61.54s)
--- PASS: TestAccWorkMailDomain_Identity_regionOverride (75.08s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/workmail   79.957s
% make t T=TestAccWorkMailDomain_List_ K=workmail
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-aws-workmail-domain 🌿...
TF_ACC=1 go1.25.8 test ./internal/service/workmail/... -v -count 1 -parallel 20 -run='TestAccWorkMailDomain_List_'  -timeout 360m -vet=off
2026/03/14 02:10:48 Creating Terraform AWS Provider (SDKv2-style)...
2026/03/14 02:10:48 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccWorkMailDomain_List_basic
=== PAUSE TestAccWorkMailDomain_List_basic
=== RUN   TestAccWorkMailDomain_List_includeResource
=== PAUSE TestAccWorkMailDomain_List_includeResource
=== RUN   TestAccWorkMailDomain_List_regionOverride
=== PAUSE TestAccWorkMailDomain_List_regionOverride
=== CONT  TestAccWorkMailDomain_List_basic
=== CONT  TestAccWorkMailDomain_List_regionOverride
=== CONT  TestAccWorkMailDomain_List_includeResource
--- PASS: TestAccWorkMailDomain_List_includeResource (51.09s)
--- PASS: TestAccWorkMailDomain_List_regionOverride (55.50s)
--- PASS: TestAccWorkMailDomain_List_basic (57.30s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/workmail   62.351s
% make t T=TestAccWorkMailDefaultDomain_basic K=workmail
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-aws-workmail-domain 🌿...
TF_ACC=1 go1.25.8 test ./internal/service/workmail/... -v -count 1 -parallel 20 -run='TestAccWorkMailDefaultDomain_basic'  -timeout 360m -vet=off
2026/03/12 04:26:26 Creating Terraform AWS Provider (SDKv2-style)...
2026/03/12 04:26:26 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccWorkMailDefaultDomain_basic
=== PAUSE TestAccWorkMailDefaultDomain_basic
=== CONT  TestAccWorkMailDefaultDomain_basic
--- PASS: TestAccWorkMailDefaultDomain_basic (65.00s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/workmail   69.910s

% make t T=TestAccWorkMailDomain_ K=workmail
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-aws-workmail-domain 🌿...
TF_ACC=1 go1.25.8 test ./internal/service/workmail/... -v -count 1 -parallel 20 -run='TestAccWorkMailDomain_'  -timeout 360m -vet=off
2026/03/12 02:15:35 Creating Terraform AWS Provider (SDKv2-style)...
2026/03/12 02:15:35 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccWorkMailDomain_basic
=== PAUSE TestAccWorkMailDomain_basic
=== RUN   TestAccWorkMailDomain_disappears
=== PAUSE TestAccWorkMailDomain_disappears
=== CONT  TestAccWorkMailDomain_basic
=== CONT  TestAccWorkMailDomain_disappears
--- PASS: TestAccWorkMailDomain_basic (53.85s)
--- PASS: TestAccWorkMailDomain_disappears (65.15s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/workmail   70.307s
 % make t T=TestAccWorkMailDefaultDomain_basic K=workmail
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-aws-workmail-domain 🌿...
TF_ACC=1 go1.25.8 test ./internal/service/workmail/... -v -count 1 -parallel 20 -run='TestAccWorkMailDefaultDomain_basic'  -timeout 360m -vet=off
2026/03/12 04:26:26 Creating Terraform AWS Provider (SDKv2-style)...
2026/03/12 04:26:26 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccWorkMailDefaultDomain_basic
=== PAUSE TestAccWorkMailDefaultDomain_basic
=== CONT  TestAccWorkMailDefaultDomain_basic
--- PASS: TestAccWorkMailDefaultDomain_basic (65.00s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/workmail   69.910s
% make t T=TestAccWorkMailDomain_Identity_ K=workmail
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-aws-workmail-domain 🌿...
TF_ACC=1 go1.25.8 test ./internal/service/workmail/... -v -count 1 -parallel 20 -run='TestAccWorkMailDomain_Identity_'  -timeout 360m -vet=off
2026/03/13 18:40:46 Creating Terraform AWS Provider (SDKv2-style)...
2026/03/13 18:40:46 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccWorkMailDomain_Identity_basic
=== PAUSE TestAccWorkMailDomain_Identity_basic
=== RUN   TestAccWorkMailDomain_Identity_regionOverride
=== PAUSE TestAccWorkMailDomain_Identity_regionOverride
=== CONT  TestAccWorkMailDomain_Identity_basic
=== CONT  TestAccWorkMailDomain_Identity_regionOverride
--- PASS: TestAccWorkMailDomain_Identity_basic (61.54s)
--- PASS: TestAccWorkMailDomain_Identity_regionOverride (75.08s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/workmail   79.957s
% make t T=TestAccWorkMailDomain_List_ K=workmail
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-aws-workmail-domain 🌿...
TF_ACC=1 go1.25.8 test ./internal/service/workmail/... -v -count 1 -parallel 20 -run='TestAccWorkMailDomain_List_'  -timeout 360m -vet=off
2026/03/14 02:10:48 Creating Terraform AWS Provider (SDKv2-style)...
2026/03/14 02:10:48 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccWorkMailDomain_List_basic
=== PAUSE TestAccWorkMailDomain_List_basic
=== RUN   TestAccWorkMailDomain_List_includeResource
=== PAUSE TestAccWorkMailDomain_List_includeResource
=== RUN   TestAccWorkMailDomain_List_regionOverride
=== PAUSE TestAccWorkMailDomain_List_regionOverride
=== CONT  TestAccWorkMailDomain_List_basic
=== CONT  TestAccWorkMailDomain_List_regionOverride
=== CONT  TestAccWorkMailDomain_List_includeResource
--- PASS: TestAccWorkMailDomain_List_includeResource (51.09s)
--- PASS: TestAccWorkMailDomain_List_regionOverride (55.50s)
--- PASS: TestAccWorkMailDomain_List_basic (57.30s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/workmail   62.351s
@github-actions
Copy link
Contributor

Community Guidelines

This comment is added to every new Pull Request to provide quick reference to how the Terraform AWS Provider is maintained. Please review the information below, and thank you for contributing to the community that keeps the provider thriving! 🚀

Voting for Prioritization

  • Please vote on this Pull Request by adding a 👍 reaction to the original post to help the community and maintainers prioritize it.
  • Please see our prioritization guide for additional information on how the maintainers handle prioritization.
  • Please do not leave +1 or other comments that do not add relevant new information or questions; they generate extra noise for others following the Pull Request and do not help prioritize the request.

Pull Request Authors

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@github-actions github-actions bot added prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. documentation Introduces or discusses updates to documentation. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. service/workmail Issues and PRs that pertain to the workmail service. generators Relates to code generators. size/XL Managed by automation to categorize the size of a PR. labels Mar 13, 2026
@subham-ibmhc subham-ibmhc added the rnd-ind-provider rnd-ind-provider label Mar 13, 2026
@subham-ibmhc subham-ibmhc marked this pull request as ready for review March 15, 2026 12:30
@subham-ibmhc subham-ibmhc requested a review from a team as a code owner March 15, 2026 12:30
@dosubot dosubot bot added new-list-resource Introduces list resource support. new-resource Introduces a new resource. labels Mar 15, 2026
Copy link
Member

@YakDriver YakDriver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this looks very solid. Just a few minor things need a little work.


## Attribute Reference

This resource does not export any additional attributes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This resource does not export any additional attributes.
This resource exports no additional attributes.


type defaultDomainResource struct {
framework.ResourceWithModel[defaultDomainResourceModel]
framework.WithNoOpDelete
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
framework.WithNoOpDelete
framework.WithNoOpDelete
framework.WithImportByIdentity

resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
names.AttrDomainName: schema.StringAttribute{
Required: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Required: true,
Required: true,
Description: "Mail domain name to set as the default.",

Required: true,
},
"organization_id": schema.StringAttribute{
Required: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Required: true,
Required: true,
Description: "Identifier of the WorkMail organization.",

conn := r.Meta().WorkMailClient(ctx)

var plan defaultDomainResourceModel
smerr.AddEnrich(ctx, &resp.Diagnostics, req.Plan.Get(ctx, &plan))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! Use of smarterr

}

var input workmail.DeregisterMailDomainInput
smerr.AddEnrich(ctx, &resp.Diagnostics, flex.Expand(ctx, &state, &input))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
smerr.AddEnrich(ctx, &resp.Diagnostics, flex.Expand(ctx, &state, &input))
smerr.AddEnrich(ctx, &resp.Diagnostics, flex.Expand(ctx, state, &input))


_, err := conn.DeregisterMailDomain(ctx, &input)
if err != nil {
if errs.IsA[*awstypes.MailDomainNotFoundException](err) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about MailDomainInUseException?

Copy link
Contributor Author

@subham-ibmhc subham-ibmhc Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked the deserializers.go, found the switch of errors expected from the API.
I think OrganizationNotFoundException and OrganizationStateException are fine to be considered as success while I decided to let other errors fall through into err != nil block to get surfaced to the user. MailDomainInUseException would suggest there is prerequisite cleanup required by user before the delete can succeed?

}
}

func (r *domainResource) flatten(ctx context.Context, domain *workmail.GetMailDomainOutput, data *domainResourceModel) (diags diag.Diagnostics) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're a little inconsistent about using named returns. It might be helpful to use named returns more.


const (
ResNameDomain = "Domain"
domainIDParts = 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used for domain and default domain, which is leaky. Probably best for default to have its own const.

Attributes: map[string]schema.Attribute{
names.AttrDomainName: schema.StringAttribute{
Required: true,
PlanModifiers: []planmodifier.String{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't do it very consistently but best for attributes to have descriptions.

% make t T=TestAccWorkMailDefaultDomain_Identity_basic K=workmail
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-aws-workmail-domain 🌿...
TF_ACC=1 go1.25.8 test ./internal/service/workmail/... -v -count 1 -parallel 20 -run='TestAccWorkMailDefaultDomain_Identity_basic'  -timeout 360m -vet=off
2026/03/20 18:31:27 Creating Terraform AWS Provider (SDKv2-style)...
2026/03/20 18:31:27 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccWorkMailDefaultDomain_Identity_basic
=== PAUSE TestAccWorkMailDefaultDomain_Identity_basic
=== CONT  TestAccWorkMailDefaultDomain_Identity_basic
--- PASS: TestAccWorkMailDefaultDomain_Identity_basic (76.14s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/workmail   81.237s
@subham-ibmhc subham-ibmhc requested a review from YakDriver March 20, 2026 14:28
Copy link
Member

@YakDriver YakDriver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

% make t T=TestAccWorkMailDomain_ K=workmail         
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-aws-workmail-domain 🌿...
TF_ACC=1 go1.25.8 test ./internal/service/workmail/... -v -count 1 -parallel 20 -run='TestAccWorkMailDomain_'  -timeout 360m -vet=off
go: downloading github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.22.7
2026/03/20 16:59:12 Creating Terraform AWS Provider (SDKv2-style)...
2026/03/20 16:59:12 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccWorkMailDomain_Identity_basic
=== PAUSE TestAccWorkMailDomain_Identity_basic
=== RUN   TestAccWorkMailDomain_Identity_regionOverride
=== PAUSE TestAccWorkMailDomain_Identity_regionOverride
=== RUN   TestAccWorkMailDomain_List_basic
=== PAUSE TestAccWorkMailDomain_List_basic
=== RUN   TestAccWorkMailDomain_List_includeResource
=== PAUSE TestAccWorkMailDomain_List_includeResource
=== RUN   TestAccWorkMailDomain_List_regionOverride
=== PAUSE TestAccWorkMailDomain_List_regionOverride
=== RUN   TestAccWorkMailDomain_basic
=== PAUSE TestAccWorkMailDomain_basic
=== RUN   TestAccWorkMailDomain_disappears
=== PAUSE TestAccWorkMailDomain_disappears
=== CONT  TestAccWorkMailDomain_Identity_basic
=== CONT  TestAccWorkMailDomain_List_regionOverride
=== CONT  TestAccWorkMailDomain_List_basic
=== CONT  TestAccWorkMailDomain_List_includeResource
=== CONT  TestAccWorkMailDomain_basic
=== CONT  TestAccWorkMailDomain_disappears
=== CONT  TestAccWorkMailDomain_Identity_regionOverride
--- PASS: TestAccWorkMailDomain_List_regionOverride (46.17s)
--- PASS: TestAccWorkMailDomain_List_basic (47.52s)
--- PASS: TestAccWorkMailDomain_Identity_regionOverride (54.22s)
--- PASS: TestAccWorkMailDomain_List_includeResource (54.62s)
--- PASS: TestAccWorkMailDomain_basic (68.70s)
--- PASS: TestAccWorkMailDomain_disappears (81.64s)
--- PASS: TestAccWorkMailDomain_Identity_basic (84.15s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/workmail	90.871s
% make t T=TestAccWorkMailDefaultDomain_ K=workmail
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-aws-workmail-domain 🌿...
TF_ACC=1 go1.25.8 test ./internal/service/workmail/... -v -count 1 -parallel 20 -run='TestAccWorkMailDefaultDomain_'  -timeout 360m -vet=off
2026/03/20 17:01:15 Creating Terraform AWS Provider (SDKv2-style)...
2026/03/20 17:01:15 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN   TestAccWorkMailDefaultDomain_Identity_basic
=== PAUSE TestAccWorkMailDefaultDomain_Identity_basic
=== RUN   TestAccWorkMailDefaultDomain_Identity_regionOverride
=== PAUSE TestAccWorkMailDefaultDomain_Identity_regionOverride
=== RUN   TestAccWorkMailDefaultDomain_basic
=== PAUSE TestAccWorkMailDefaultDomain_basic
=== CONT  TestAccWorkMailDefaultDomain_Identity_basic
=== CONT  TestAccWorkMailDefaultDomain_basic
=== CONT  TestAccWorkMailDefaultDomain_Identity_regionOverride
--- PASS: TestAccWorkMailDefaultDomain_basic (43.38s)
--- PASS: TestAccWorkMailDefaultDomain_Identity_regionOverride (48.56s)
--- PASS: TestAccWorkMailDefaultDomain_Identity_basic (52.31s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/workmail	58.652s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Introduces or discusses updates to documentation. generators Relates to code generators. new-list-resource Introduces list resource support. new-resource Introduces a new resource. prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. rnd-ind-provider rnd-ind-provider service/workmail Issues and PRs that pertain to the workmail service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants